package com.summer.JUnit.case1;

import com.summer.JUnit.case1.StackExercise.StackEmptyException;
import com.summer.JUnit.case1.StackExerciseImpl.IllegalityStackSizeException;

public class TestStackExercise extends BaseTestCase {

	private StackExercise stack;
	
	public TestStackExercise(String method){
		super(method);
	}
	
	public void testAction(){
		assertEquals(4, 2+2);
	}
	
	public void testInit(){
		try {
			StackExercise stackTmp = new StackExerciseImpl(0);
			stackTmp = new StackExerciseImpl(-1);
			fail("Illegality Stack Size Exception");
			stackTmp.push("err");
		} catch (IllegalityStackSizeException e) {
			assertTrue(true);
		}
	}
	
	public void testPush(){
		try {
			stack.push("sample");
			assertEquals("sample", stack.pop());
		} catch (StackEmptyException e) {
			e.printStackTrace();
		}
	}
	
	public void testOverflow(){
		String[] strList = {"one","two","three","four"};
		for(String str : strList){
			stack.push(str);
		}
		for(String str : strList){
			try {
				assertEquals(str, stack.pop());
			} catch (StackEmptyException e) {
				e.printStackTrace();
			}
		}
	}
	
	public void testEmptyStack(){
		try {
			stack.pop();
			fail("Stack Empty Exception");
		} catch (StackEmptyException e) {
			assertTrue(true);
		}
	}

	@Override
	protected void setUp() throws Exception {
		stack = new StackExerciseImpl(3);
	}

	@Override
	protected void tearDown() throws Exception {
		stack = null;
	}
	
	
}
